package cn.congzhou.crm.utils;

import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.IOException;

//编写类继承FreeMarkerConfigurer
public class MyFreeMarkerConfigurer extends FreeMarkerConfigurer{

    @Autowired
    private ExceptionUtil eu;

    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
//      集成后要还要调用父类的配置方法，不然很多配置都不能用
        super.afterPropertiesSet();
//      获取Configuration对象
        Configuration cfg = this.getConfiguration();
        //注册 freemarker 页面异常处理器
        cfg.setTemplateExceptionHandler(eu);
//      注册shiro标签
        cfg.setSharedVariable("shiro", new ShiroTags());//shiro标签
    }
}
